package com.jch.thread_info;

public class JavaThreadClassCreationAndRun {

    public static void main(String[] args) {
        // 当前线程，即main线程，在该线程下创建并运行的线程就是其子线程。
        System.out.println("Current Thread Name:" + Thread.currentThread().getName());
        Example example = new Example("Java Thread creation and running.");
        // 创建Thread实例，可以看做main线程的子线程
        Thread thread = new Thread(example);
        // 设置线程名称
        thread.setName("ExampleThread");
        // 启动 thread 线程
        thread.start();
        System.out.println("thread name:" + thread.getName());
        System.out.println("ExampleThread is running:" + thread.isAlive());

    }

    static class Example implements Runnable{

        private String message;

        public Example(String msg) {
            this.message = msg;
        }

        private void outMessage(String msg){
            System.out.println("thread:"+Thread.currentThread().getName() + ", msg:" + msg);
        }

        @Override
        public void run() {
            outMessage(message);
        }
    }

}
